package sz.szsmk.citizencard.ui.dzsmkfragment;

import android.app.Activity;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.ExpandableListView;

import sz.szsmk.citizencard.R;
import sz.szsmk.citizencard.widget.MyExpandableListView;

public class ElecCitizenCardFragment extends Fragment implements ExpandableListView.OnGroupExpandListener, ExpandableListView.OnChildClickListener {
    protected View view;

    MyExpandableListView listView;
    MyAdapter myAdapter;
    private Activity context;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable
            Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_eleccitizen_card, container, false);

        listView = view.findViewById(R.id.listView);

        context = getActivity();
        myAdapter = new MyAdapter();
        listView.setAdapter(myAdapter);
        listView.setOnGroupExpandListener(this);
        listView.setOnChildClickListener(this);
        listView.expandGroup(0);

        return view;
    }

    @Override
    public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
        return false;
    }

    @Override
    public void onGroupExpand(int groupPosition) {

    }

    public class MyAdapter extends BaseExpandableListAdapter {


        @Override
        public int getGroupCount() {
            return 3;
//            return list == null || list.size() == 0 ? 0 : list.size();
        }

        @Override
        public int getChildrenCount(int i) {
            return 3;
//            return list == null || list.size() == 0 || list.get(i).getItlList() == null || list.get(i).getItlList().size() == 0 ? 0 : list.get(i).getItlList().size();
        }

        @Override
        public Object getGroup(int groupPosition) {
            return null;
        }

        @Override
        public Object getChild(int groupPosition, int childPosition) {
            return null;
        }

        @Override
        public long getGroupId(int i) {
            return i;
        }

        @Override
        public long getChildId(int i, int i1) {
            return i;
        }

        @Override
        public boolean hasStableIds() {
            return true;
        }

        @Override
        public int getChildTypeCount() {
            return 3;
//            return list == null || list.size() == 0 ? 0 : list.size();
        }

        @Override
        public int getChildType(int groupPosition, int childPosition) {
            return groupPosition;
        }

        @Override
        public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
            ViewHolder2 holder = null;
            if (convertView == null) {
                convertView = context.getLayoutInflater().inflate(R.layout.item_elec_card, parent, false);
                holder = new ViewHolder2(convertView);
                convertView.setTag(holder);
            } else {
                holder = (ViewHolder2) convertView.getTag();
            }
           return convertView;
        }

        @Override
        public View getChildView(int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
            ViewHolder holder = null;
            if (convertView == null) {
                convertView = context.getLayoutInflater().inflate(R.layout.item_elec_card_child, parent, false);
                holder = new ViewHolder(convertView);
                convertView.setTag(holder);
            } else {
                holder = (ViewHolder) convertView.getTag();
            }

            return convertView;
        }

        @Override
        public boolean isChildSelectable(int i, int i1) {
            return true;
        }

    }

    class ViewHolder2 {

        ViewHolder2(View view) {
        }
    }

    class ViewHolder {

        ViewHolder(View view) {
        }
    }
}
